package com.myway.utils;

import java.text.SimpleDateFormat;
import java.util.Date;


public class OrderNumberGenerator<T> extends Thread{

    private static long orderNum = 0l;
    private static String date ;

    public static void main(String[] args) throws InterruptedException {
        for (int i = 0; i < 1000; i++) {
            System.out.println(OrderNumberGenerator.getOrderNo());
            Thread.sleep(1000);
        }
    }

    /**
     * 生成订单编号
     * @return
     */
    public static synchronized long getOrderNo() {
        String random=(int)((Math.random()*9+1)*1000)+"";
        String str = new SimpleDateFormat("yyMMddHHmmss").format(new Date());
        if(date==null||!date.equals(str)){
            date = str;
        }
        date+=random;
        long orderNo = Long.parseLong((date));
        return orderNo;
    }







}